#!/usr/bin/make -f
# -*- makefile -*-

SVN_URL := https://svn.blender.org/svnroot/bf-blender/trunk/blender
REV := $(shell dpkg-parsechangelog | sed -rne 's,^Version: .*[+~]svn([0-9]+).*,\1,p')
VER := $(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p')
REL := $(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]+\.[0-9]+).*,\1,p')
TARBALL = blender_$(VER).orig.tar.gz
BLDDIR = debian/cmake

%:
	dh $@ -Scmake -B$(BLDDIR) --parallel --with python3 --without python-support

override_dh_auto_configure:
	# blender spesific CMake options
	dh_auto_configure -- \
		-DCMAKE_BUILD_TYPE:STRING=Release \
		-DWITH_INSTALL_PORTABLE:BOOL=OFF \
		-DWITH_PYTHON_INSTALL:BOOL=OFF \
		-DWITH_OPENCOLLADA:BOOL=OFF

override_dh_auto_test:
	# don't run CTest

override_dh_install:
	dh_install

	# remove duplicated docs
	rm -rf debian/blender-snapshot/usr/share/doc/blender

override_dh_python3:
	dh_python3 -V 3.2-3.3 /usr/share/blender/$(REL)/scripts

get-orig-source:
	rm -rf get-orig-source $(TARBALL)
	mkdir get-orig-source
	if [ "$(SVN_URL)" = . ] && [ `svnversion` = "$(REV)" ]; then \
		svn -q export . get-orig-source/blender-$(VER); \
	else \
		svn -q export -r $(REV) $(SVN_URL) get-orig-source/blender-$(VER); \
	fi
	GZIP='--best --no-name' tar czf $(TARBALL) -C get-orig-source blender-$(VER)
	rm -rf get-orig-source
	@echo "$(TARBALL) created; move it to the right destination to build the package"
